package com.sqsf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.sqsf.entity.User;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public String listUsers(Model model) {
        List<User> users = userService.selectAllUsers();
        model.addAttribute("users", users);
        return "userList";
    }
    @PostMapping("/add")
    public String addUser(User user) {
        userService.insertUser(user);
        return "redirect:/user/list";
    }

}
